package ssm.controller;

import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;
import ssm.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import ssm.pojo.Order;
import ssm.pojo.User;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by sally on 2016/8/16.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/orders")
    public ModelAndView ListAll(HttpServletRequest request, HttpServletResponse response) {
        List<Order> orders = userMapper.getUserOrders(1);
        System.out.println("orders");
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("orders", orders);
        return mav;
    }

    @RequestMapping("test")
    public String Test(Model model) {
        int userId = 3;
        User user = this.userMapper.getUserById(userId);
        model.addAttribute("user", user);
        return "index";
    }
}
